from selenium.webdriver.common.by import By

from common.Utils import ForumDriver

class LoginTest:
    url=""
    driver=""
    def __init__(self):
        self.url="http://127.0.0.1:9580/sign-in.html"
        self.driver=ForumDriver.driver
        self.driver.get(self.url)

    #正常登录测试用例
    def LoginSucTest(self):
        self.driver.find_element(By.CSS_SELECTOR,"#username").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#password").clear()
        #已注册的用户名
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("zhangsan")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        #找到论坛的图标，说明登录成功
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > h1 > a > img")
        #添加截图
        ForumDriver.getScreenShot()
        #返回登录页面
        self.driver.back()

    #异常登录测试用例
    def LoginFailTest(self):
        #1.用户名和密码均为空
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        #输入框下方出现提示语句
        self.driver.find_element(By.CSS_SELECTOR,"#signInForm > div.mb-3 > div")
        self.driver.find_element(By.CSS_SELECTOR,"#signInForm > div.mb-2 > div > div")
        ForumDriver.getScreenShot()

        #2.未注册的用户名
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("wangwu")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        #出现警告：用户名或密码错误
        self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2")
        ForumDriver.getScreenShot()



